package com.gzwl.service.employee;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gzwl.dao.EmployeeMapper;
import com.gzwl.uitls.ResultUtil;
import com.gzwl.vo.Employee;
import com.gzwl.vo.EmployeeExample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public ResultUtil<Employee> itemsEmployees(int index, int size) {
        PageHelper.startPage(index, size);
        EmployeeExample example = new EmployeeExample();
        EmployeeExample.Criteria criteria = example.createCriteria();
        // 不显示超级管理员
        criteria.andEmployeeIdNotEqualTo(1);
        List<Employee> list = employeeMapper.selectByExample(example);
        PageInfo<Employee> pageInfo = new PageInfo<Employee>(list);
        ResultUtil<Employee> resultUtil = new ResultUtil<Employee>();
        resultUtil.setCount(pageInfo.getTotal());
        resultUtil.setData(pageInfo.getList());
        resultUtil.setCode(0);
        return resultUtil;
    }

    @Override
    public Employee getEmployeeByID(int id) {
        return employeeMapper.selectByPrimaryKey(id);
    }

    @Override
    public void delEmployeeByID(int id) {
        if (null != getEmployeeByID(id)) {
            employeeMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public void addEmployee(Employee employee) {
        employeeMapper.insertSelective(employee);
    }

    @Override
    public void updateEmployee(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
    }

}
